/*     */ package com.zimbra.cs.fb;
/*     */ 
/*     */ import com.microsoft.schemas.exchange.services._2006.types.MapiPropertyTypeType;
/*     */ import com.microsoft.schemas.exchange.services._2006.types.NonEmptyArrayOfPropertyValuesType;
/*     */ import com.microsoft.schemas.exchange.services._2006.types.PathToExtendedFieldType;
/*     */ import com.zimbra.common.localconfig.LC;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import java.util.ArrayList;
/*     */ import java.util.HashMap;
/*     */ import java.util.LinkedList;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class ExchangeEWSMessage
/*     */   extends ExchangeMessage
/*     */ {
/*  35 */   public static final PathToExtendedFieldType PidTagScheduleInfoMonthsTentative = new PathToExtendedFieldType();
/*     */   
/*  37 */   public static final PathToExtendedFieldType PidTagScheduleInfoFreeBusyTentative = new PathToExtendedFieldType();
/*     */   
/*  39 */   public static final PathToExtendedFieldType PidTagScheduleInfoMonthsBusy = new PathToExtendedFieldType();
/*     */   
/*  41 */   public static final PathToExtendedFieldType PidTagScheduleInfoFreeBusyBusy = new PathToExtendedFieldType();
/*     */   
/*  43 */   public static final PathToExtendedFieldType PidTagScheduleInfoMonthsAway = new PathToExtendedFieldType();
/*     */   
/*  45 */   public static final PathToExtendedFieldType PidTagScheduleInfoFreeBusyAway = new PathToExtendedFieldType();
/*     */   
/*  47 */   public static final PathToExtendedFieldType PidTagScheduleInfoMonthsMerged = new PathToExtendedFieldType();
/*     */   
/*  49 */   public static final PathToExtendedFieldType PidTagScheduleInfoFreeBusyMerged = new PathToExtendedFieldType();
/*     */   
/*  51 */   public static final PathToExtendedFieldType PidTagFreeBusyPublishStart = new PathToExtendedFieldType();
/*     */   
/*  53 */   public static final PathToExtendedFieldType PidTagFreeBusyPublishEnd = new PathToExtendedFieldType();
/*     */   
/*  55 */   public static final PathToExtendedFieldType PidTagFreeBusyRangeTimestamp = new PathToExtendedFieldType();
/*     */   
/*  57 */   public static final PathToExtendedFieldType PidTagFreeBusyMessageEmailAddress = new PathToExtendedFieldType();
/*     */   
/*     */   static
/*     */   {
/*  61 */     PidTagScheduleInfoMonthsTentative.setPropertyTag("0x6851");
/*  62 */     PidTagScheduleInfoMonthsTentative.setPropertyType(MapiPropertyTypeType.INTEGER_ARRAY);
/*  63 */     PidTagScheduleInfoFreeBusyTentative.setPropertyTag("0x6852");
/*  64 */     PidTagScheduleInfoFreeBusyTentative.setPropertyType(MapiPropertyTypeType.BINARY_ARRAY);
/*     */     
/*  66 */     PidTagScheduleInfoMonthsBusy.setPropertyTag("0x6853");
/*  67 */     PidTagScheduleInfoMonthsBusy.setPropertyType(MapiPropertyTypeType.INTEGER_ARRAY);
/*  68 */     PidTagScheduleInfoFreeBusyBusy.setPropertyTag("0x6854");
/*  69 */     PidTagScheduleInfoFreeBusyBusy.setPropertyType(MapiPropertyTypeType.BINARY_ARRAY);
/*     */     
/*  71 */     PidTagScheduleInfoMonthsAway.setPropertyTag("0x6855");
/*  72 */     PidTagScheduleInfoMonthsAway.setPropertyType(MapiPropertyTypeType.INTEGER_ARRAY);
/*  73 */     PidTagScheduleInfoFreeBusyAway.setPropertyTag("0x6856");
/*  74 */     PidTagScheduleInfoFreeBusyAway.setPropertyType(MapiPropertyTypeType.BINARY_ARRAY);
/*     */     
/*  76 */     PidTagScheduleInfoMonthsMerged.setPropertyTag("0x684F");
/*  77 */     PidTagScheduleInfoMonthsMerged.setPropertyType(MapiPropertyTypeType.INTEGER_ARRAY);
/*  78 */     PidTagScheduleInfoFreeBusyMerged.setPropertyTag("0x6850");
/*  79 */     PidTagScheduleInfoFreeBusyMerged.setPropertyType(MapiPropertyTypeType.BINARY_ARRAY);
/*     */     
/*  81 */     PidTagFreeBusyPublishStart.setPropertyTag("0x6847");
/*  82 */     PidTagFreeBusyPublishStart.setPropertyType(MapiPropertyTypeType.INTEGER);
/*     */     
/*  84 */     PidTagFreeBusyPublishEnd.setPropertyTag("0x6848");
/*  85 */     PidTagFreeBusyPublishEnd.setPropertyType(MapiPropertyTypeType.INTEGER);
/*     */     
/*  87 */     PidTagFreeBusyRangeTimestamp.setPropertyTag("0x6868");
/*  88 */     PidTagFreeBusyRangeTimestamp.setPropertyType(MapiPropertyTypeType.SYSTEM_TIME);
/*     */     
/*  90 */     PidTagFreeBusyMessageEmailAddress.setPropertyTag("0x6849");
/*  91 */     PidTagFreeBusyMessageEmailAddress.setPropertyType(MapiPropertyTypeType.STRING);
/*     */   }
/*     */   
/*     */   public ExchangeEWSMessage(String ou, String cn, String mail) {
/*  95 */     super(ou, cn, mail);
/*     */   }
/*     */   
/*     */   Map<PathToExtendedFieldType, NonEmptyArrayOfPropertyValuesType> GetFreeBusyProperties(FreeBusy fb)
/*     */   {
/* 100 */     Map<PathToExtendedFieldType, NonEmptyArrayOfPropertyValuesType> ret = new HashMap();
/*     */     
/*     */ 
/* 103 */     long startMonth = millisToMonths(fb.getStartTime());
/* 104 */     long endMonth = millisToMonths(fb.getEndTime());
/* 105 */     FreeBusy.IntervalList consolidated = new FreeBusy.IntervalList(fb.getStartTime(), fb.getEndTime());
/*     */     
/*     */ 
/* 108 */     ArrayList<String> busyMonths = new ArrayList();
/* 109 */     ArrayList<byte[]> busyEvents = new ArrayList();
/* 110 */     ArrayList<String> tentativeMonths = new ArrayList();
/* 111 */     ArrayList<byte[]> tentativeEvents = new ArrayList();
/* 112 */     ArrayList<String> oofMonths = new ArrayList();
/* 113 */     ArrayList<byte[]> oofEvents = new ArrayList();
/* 114 */     ArrayList<String> allMonths = new ArrayList();
/* 115 */     ArrayList<byte[]> allEvents = new ArrayList();
/*     */     
/* 117 */     encodeIntervals(fb, startMonth, endMonth, "B", busyMonths, busyEvents, consolidated);
/* 118 */     encodeIntervals(fb, startMonth, endMonth, "T", tentativeMonths, tentativeEvents, consolidated);
/* 119 */     encodeIntervals(fb, startMonth, endMonth, "O", oofMonths, oofEvents, consolidated);
/* 120 */     encodeIntervals(consolidated, startMonth, endMonth, "B", allMonths, allEvents, null);
/*     */     
/* 122 */     if ((tentativeMonths.size() > 0) && (tentativeEvents.size() > 0)) {
/* 123 */       NonEmptyArrayOfPropertyValuesType nonEmptyTentativeMonths = new NonEmptyArrayOfPropertyValuesType();
/*     */       
/* 125 */       nonEmptyTentativeMonths.getValue().addAll(tentativeMonths);
/* 126 */       ret.put(PidTagScheduleInfoMonthsTentative, nonEmptyTentativeMonths);
/* 127 */       NonEmptyArrayOfPropertyValuesType nonEmptyTentativeEvents = new NonEmptyArrayOfPropertyValuesType();
/*     */       
/* 129 */       for (byte[] buf : tentativeEvents) {
/* 130 */         nonEmptyTentativeEvents.getValue().add(encodeBase64LittleEndian(buf));
/*     */       }
/*     */       
/* 133 */       ret.put(PidTagScheduleInfoFreeBusyTentative, nonEmptyTentativeEvents);
/*     */     }
/*     */     
/* 136 */     if ((busyMonths.size() > 0) && (busyEvents.size() > 0)) {
/* 137 */       NonEmptyArrayOfPropertyValuesType nonEmptyBusyMonths = new NonEmptyArrayOfPropertyValuesType();
/*     */       
/* 139 */       nonEmptyBusyMonths.getValue().addAll(busyMonths);
/* 140 */       ret.put(PidTagScheduleInfoMonthsBusy, nonEmptyBusyMonths);
/* 141 */       NonEmptyArrayOfPropertyValuesType nonEmptyBusyEvents = new NonEmptyArrayOfPropertyValuesType();
/*     */       
/* 143 */       for (byte[] buf : busyEvents) {
/* 144 */         nonEmptyBusyEvents.getValue().add(encodeBase64LittleEndian(buf));
/*     */       }
/*     */       
/* 147 */       ret.put(PidTagScheduleInfoFreeBusyBusy, nonEmptyBusyEvents);
/*     */     }
/* 149 */     if ((oofMonths.size() > 0) && (oofEvents.size() > 0)) {
/* 150 */       NonEmptyArrayOfPropertyValuesType nonEmptyOofMonths = new NonEmptyArrayOfPropertyValuesType();
/*     */       
/* 152 */       nonEmptyOofMonths.getValue().addAll(oofMonths);
/* 153 */       ret.put(PidTagScheduleInfoMonthsAway, nonEmptyOofMonths);
/* 154 */       NonEmptyArrayOfPropertyValuesType nonEmptyOofEvents = new NonEmptyArrayOfPropertyValuesType();
/*     */       
/* 156 */       for (byte[] buf : oofEvents) {
/* 157 */         nonEmptyOofEvents.getValue().add(encodeBase64LittleEndian(buf));
/*     */       }
/* 159 */       ret.put(PidTagScheduleInfoFreeBusyAway, nonEmptyOofEvents);
/*     */     }
/* 161 */     if ((allMonths.size() > 0) && (allEvents.size() > 0)) {
/* 162 */       NonEmptyArrayOfPropertyValuesType nonEmptyAllMonths = new NonEmptyArrayOfPropertyValuesType();
/*     */       
/* 164 */       nonEmptyAllMonths.getValue().addAll(allMonths);
/* 165 */       ret.put(PidTagScheduleInfoMonthsMerged, nonEmptyAllMonths);
/* 166 */       NonEmptyArrayOfPropertyValuesType nonEmptyAllEvents = new NonEmptyArrayOfPropertyValuesType();
/*     */       
/* 168 */       for (byte[] buf : allEvents) {
/* 169 */         nonEmptyAllEvents.getValue().add(encodeBase64LittleEndian(buf));
/*     */       }
/* 171 */       ret.put(PidTagScheduleInfoFreeBusyMerged, nonEmptyAllEvents);
/*     */     }
/*     */     
/* 174 */     NonEmptyArrayOfPropertyValuesType fbStartTime = new NonEmptyArrayOfPropertyValuesType();
/*     */     
/* 176 */     fbStartTime.getValue().add(String.valueOf(lMinutesSinceMsEpoch(fb.getStartTime())));
/*     */     
/* 178 */     ret.put(PidTagFreeBusyPublishStart, fbStartTime);
/* 179 */     NonEmptyArrayOfPropertyValuesType fbEndTime = new NonEmptyArrayOfPropertyValuesType();
/*     */     
/* 181 */     fbEndTime.getValue().add(String.valueOf(lMinutesSinceMsEpoch(fb.getEndTime())));
/*     */     
/* 183 */     ret.put(PidTagFreeBusyPublishEnd, fbEndTime);
/* 184 */     NonEmptyArrayOfPropertyValuesType nonEmptyEmailAddress = new NonEmptyArrayOfPropertyValuesType();
/*     */     
/* 186 */     nonEmptyEmailAddress.getValue().add(this.mOu + getRcpt(LC.freebusy_exchange_cn3) + this.mCn);
/*     */     
/* 188 */     ret.put(PidTagFreeBusyMessageEmailAddress, nonEmptyEmailAddress);
/*     */     
/* 190 */     return ret;
/*     */   }
/*     */   
/*     */ 
/*     */   private void encodeIntervals(Iterable<FreeBusy.Interval> fb, long startMonth, long endMonth, String type, ArrayList<String> months, ArrayList<byte[]> events, FreeBusy.IntervalList consolidated)
/*     */   {
/* 196 */     HashMap<Long, LinkedList<Byte>> fbMap = new HashMap();
/*     */     
/* 198 */     for (long i = startMonth; i <= endMonth; i += 1L)
/* 199 */       fbMap.put(Long.valueOf(i), new LinkedList());
/* 200 */     for (FreeBusy.Interval interval : fb) {
/* 201 */       String status = interval.getStatus();
/* 202 */       if (status.equals(type)) {
/* 203 */         LinkedList<Byte> buf = (LinkedList)fbMap.get(Long.valueOf(millisToMonths(interval.getStart())));
/*     */         
/* 205 */         encodeFb(interval.getStart(), interval.getEnd(), buf);
/* 206 */         if (consolidated != null) {
/* 207 */           consolidated.addInterval(new FreeBusy.Interval(interval.getStart(), interval.getEnd(), "B"));
/*     */         }
/*     */       }
/*     */     }
/*     */     
/* 212 */     for (long m = startMonth; m <= endMonth; m += 1L) {
/* 213 */       LinkedList<Byte> encodedList = (LinkedList)fbMap.get(Long.valueOf(m));
/* 214 */       byte[] raw = new byte[0];
/* 215 */       if (encodedList.size() > 0) {
/*     */         try {
/* 217 */           raw = new byte[encodedList.size()];
/* 218 */           for (int i = 0; i < encodedList.size(); i++)
/* 219 */             raw[i] = ((Byte)encodedList.get(i)).byteValue();
/*     */         } catch (Exception e) {
/* 221 */           ZimbraLog.fb.warn("error converting millis to minutes for month " + m, e);
/*     */           
/*     */ 
/* 224 */           continue;
/*     */         }
/*     */       }
/* 227 */       if (0 != raw.length) {
/* 228 */         months.add(Long.toString(m));
/* 229 */         events.add(raw);
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   protected Long lMinutesSinceMsEpoch(long millis)
/*     */   {
/* 238 */     Long mins = Long.valueOf((millis / 1000L + 11644473600L) / 60L);
/*     */     
/* 240 */     return mins;
/*     */   }
/*     */   
/*     */   public static String encodeBase64LittleEndian(byte[] vby) {
/* 244 */     String charSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
/*     */     
/* 246 */     byte[] encodeData = new byte[64];
/* 247 */     for (int i = 0; i < 64; i++) {
/* 248 */       byte c = (byte)"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(i);
/* 249 */       encodeData[i] = c;
/*     */     }
/* 251 */     int length = vby.length;
/* 252 */     int start = 0;
/* 253 */     byte[] dst = new byte[(length + 2) / 3 * 4 + length / 72];
/* 254 */     int x = 0;
/* 255 */     int dstIndex = 0;
/* 256 */     int state = 0;
/* 257 */     int old = 0;
/* 258 */     int len = 0;
/* 259 */     int max = length + start;
/* 260 */     for (int srcIndex = start; srcIndex < max; srcIndex++) {
/* 261 */       x = vby[srcIndex];
/* 262 */       state++; switch (state) {
/*     */       case 1: 
/* 264 */         dst[(dstIndex++)] = encodeData[(x >> 2 & 0x3F)];
/* 265 */         break;
/*     */       case 2: 
/* 267 */         dst[(dstIndex++)] = encodeData[(old << 4 & 0x30 | x >> 4 & 0xF)];
/*     */         
/* 269 */         break;
/*     */       case 3: 
/* 271 */         dst[(dstIndex++)] = encodeData[(old << 2 & 0x3C | x >> 6 & 0x3)];
/*     */         
/* 273 */         dst[(dstIndex++)] = encodeData[(x & 0x3F)];
/* 274 */         state = 0;
/*     */       }
/*     */       
/* 277 */       old = x;
/* 278 */       len++; if (len >= 72) {
/* 279 */         dst[(dstIndex++)] = 10;
/* 280 */         len = 0;
/*     */       }
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 287 */     switch (state) {
/*     */     case 1: 
/* 289 */       dst[(dstIndex++)] = encodeData[(old << 4 & 0x30)];
/* 290 */       dst[(dstIndex++)] = 61;
/* 291 */       dst[(dstIndex++)] = 61;
/* 292 */       break;
/*     */     case 2: 
/* 294 */       dst[(dstIndex++)] = encodeData[(old << 2 & 0x3C)];
/* 295 */       dst[(dstIndex++)] = 61;
/*     */     }
/*     */     
/* 298 */     return new String(dst);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/fb/ExchangeEWSMessage.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */